package GUI;
/**
 * Student view personal data screen
 */

import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;

import Common.Course;
import Common.Courses;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class ViewPersonalData extends JPanel {
	//private JPanel PersonalDataPanel=null;
	private JLabel lblViewPersonalData=null;
	private JLabel lblSelectYear=null;
	private JLabel lblSelectCourse=null;
	
	
	private JLabel lblSelectSemester=null;
	private JComboBox comboBoxSelSemester=null;
	private JComboBox comboBoxSelYear=null; 
	private JComboBox comboBoxSelCourse=null;
	private JButton btnShowData=null;
	private Dimension defaultDim = null;
	public Login myLoginFrame = null;
	public UserStudent user=null;
	private Vector<String> courseDetails=null;
	private JButton btnViewCheckedAssignments = null;
	private ShowDataScreen dataScreen=null;
	private ViewCheckedAssignmentScreen checkedAssignmentScr=null;
	public StudentMainMenu stmn=null;
	

	
	//View checked assigments
	
	 private JLabel lblSelectCheckedAssignment=null;
	
	
	//public StudentMainMenu myFrame=null; 
	
	
	
	
	public JButton getShowDataButton()
	{
		if (btnShowData==null)
		{
			 btnShowData = new JButton("Show Data");
			 btnShowData.addActionListener(new java.awt.event.ActionListener() {
			 	public void actionPerformed(java.awt.event.ActionEvent e) {
			 		dataScreen=null;
			 		stmn.user.SetSemester(comboBoxSelSemester.getSelectedItem().toString());
			 		stmn.user.SetYear(comboBoxSelYear.getSelectedItem().toString());
			 		stmn.user.SetCourse(comboBoxSelCourse.getSelectedItem().toString());
			 		System.out.println("ALON" + stmn.user.getYear() + " " +stmn.user.getCourse() +" " +stmn.user.getSem() );
			 		dataScreen=getShowDataScreen();
			 		
			 		
			 		
			 		stmn.setContentPane(dataScreen);
			 		//stmn.pack();
			 		
			 	}
			 });
			btnShowData.setBounds(330, 231, 124, 23);
			//TODO add action listener
			
		}
		return btnShowData;
	}
	
	
	public JButton getViewCheckedAssignmentsButton()
	{
				 
		if (btnViewCheckedAssignments==null)
		{
			 btnViewCheckedAssignments = new JButton("View checked assignments");
			 btnViewCheckedAssignments.addActionListener(new java.awt.event.ActionListener() {
			 	public void actionPerformed(java.awt.event.ActionEvent e) {
			 		//dataScreen=null;
			 		stmn.user.SetSemester(comboBoxSelSemester.getSelectedItem().toString());
			 		stmn.user.SetYear(comboBoxSelYear.getSelectedItem().toString());
			 		stmn.user.SetCourse(comboBoxSelCourse.getSelectedItem().toString());
			 		System.out.println("ALON" + stmn.user.getYear() + " " +stmn.user.getCourse() +" " +stmn.user.getSem() );
			 		checkedAssignmentScr=null;
			 		checkedAssignmentScr=stmn.getCheckedAssignmentScr();
			 		stmn.setContentPane(checkedAssignmentScr);
			 		
			 			 		
			 		
			 		
			 	}
			 });
			 btnViewCheckedAssignments.setBounds(330, 289, 161, 23);
			
		}
		return btnViewCheckedAssignments;
	}
	
	private void initialize(StudentMainMenu stmn)
	{
	this.setSize(getMaximumSize());
	this.setLayout(null);
	
		
	 lblViewPersonalData = new JLabel("View student info");
   	 lblViewPersonalData.setBounds(208, 11, 83, 14);
	
   	 lblSelectYear = new JLabel("Select Year:");
   	 lblSelectYear.setBounds(39, 71, 58, 14);
   	 
     lblSelectSemester = new JLabel("Select Semester:");
	 lblSelectSemester.setBounds(39, 116, 81, 14);
	 
	 lblSelectCourse = new JLabel("Select Course:");
	 lblSelectCourse.setBounds(39, 161, 70, 14);
	 
	 
	 this.add(lblViewPersonalData);
	 this.add(lblSelectYear);
	 this.add(lblSelectSemester);
	 this.add(lblSelectCourse);
	
	 this.add(getComboBoxSelYear(stmn.user.StudentData.Years));
	 this.add(getComboBoxSelSemester(stmn.user.StudentData.Semesters));
	 this.add(getComboBoxSelCourse(stmn.user.StudentData.ListOfCourses));
	 this.add(getShowDataButton());
	 this.add(getViewCheckedAssignmentsButton());
}
	
	public JComboBox getComboBoxSelYear(Vector<String> years)
	{

		
		if(comboBoxSelYear==null)
		{
		comboBoxSelYear	= new JComboBox(years);
		comboBoxSelYear.setBounds(163, 67, 158, 22);
			
		
		}
		return comboBoxSelYear;
	}
	
	public JComboBox getComboBoxSelSemester(Vector<String> semesters)
	{
		if(comboBoxSelSemester==null)
		{
		comboBoxSelSemester = new JComboBox(semesters);
		comboBoxSelSemester.setBounds(163, 112, 158, 22);
		
		//TODO add available semesters the year selected above for this student
		}
	
		return comboBoxSelSemester;
		
	}
	
	public JComboBox getComboBoxSelCourse(Courses courses)
	{
		
		int i;
	
		courseDetails = new Vector<String>();
		for(i=0;i<courses.lOfCourses.size();i++)
		{
		
			courseDetails.addElement(courses.lOfCourses.get(i).getCname()+ " " + courses.lOfCourses.get(i).getCid());
		}
			
		if(comboBoxSelCourse==null)
		{
		
			
			comboBoxSelCourse = new JComboBox(courseDetails);
			comboBoxSelCourse.setBounds(163, 157, 158, 22);
			comboBoxSelCourse.setVisible(true);
			
		
			
			
			//TODO add available courses for the selected semester above for the year selected above for this student
		}
		return comboBoxSelCourse;
	}
	
	
	
	public ViewPersonalData(StudentMainMenu stmn) {
		super();
		initialize(stmn);

	}
	
	
	public ShowDataScreen getShowDataScreen()
	{
	
		
		if(dataScreen==null)
		{
			dataScreen=new ShowDataScreen(stmn);
			dataScreen.setSize(getMaximumSize());
			
			//dataScreen.user=stmn.user;
		
			
		}
		return dataScreen;
	}
}
